<?php

namespace App\Console\Commands;

use App\Models\Period;
use Illuminate\Console\Command;

class VerifyHistoryPeriod extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'verify:history-period {--months-ago=4}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Verify history period';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $monthsAgo = $this->option('months-ago');
        $this->info("Verifying history period for $monthsAgo months ago");
        $day = now()->subMonths($monthsAgo);
        $this->info("Day: $day");
        $update = Period::where('start_date', '<=', $day)->where('status', 1)->update(['status' => 2]);
        $this->info("Updated $update records");
    }
}
